Skip to content

Conversation

thomasp85
Copy link
Member

Fix #4141

This PR fixes label_bquote() so it can once again look up functions etc from the calling environment

@thomasp85 thomasp85 added this to the ggplot2 3.3.4 milestone Apr 27, 2021
@thomasp85 thomasp85 requested a review from clauswilke April 27, 2021 11:51
Copy link
Member

@clauswilke clauswilke left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, but maybe add a test for this functionality?

@thomasp85 thomasp85 merged commit 53c1440 into master Apr 29, 2021
@bk1n
Copy link

bk1n commented Aug 18, 2025

I think this has caused some issues with using label_bquote inside functions. I am trying to use this inside a function e.g.

translator = c('name' ='fancy[name]') # or some other kind of plotmath (e.g. from latex2exp)

fun = function(i) {
    x = data[[i]]
    m = vec[i]

    ggplot(x, aes(x = x, y = y) +
        facet_grid(
            cols = vars(measure),
            labeller = label_bquote(cols = .(translator[m]))
        )
}

Would give an error on not being able to find m - as m is only defined in rlang::caller_env(), not rlang::env_parent().

I changed rlang::env_parent() to rlang::caller_env() in labeller.R and it fixed this issue.

Maybe there should be a way to make both environments accessible to label_bquote?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

rlang::sym not recognized within label_bquote
3 participants